from selenium import webdriver
from unittest import TestCase
from  ddt import ddt,data,unpack
from Logon_Data import LogonData
from Logon_Operation import LogonOperation
from Logon_Excel import Exel_options
@ddt
class TestWeb(TestCase):
    @data(*LogonData.logon_success_data)
    @unpack
    def testLogonSuccess(self,name,pwd,repwd,expect,row):
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://192.168.72.135:90")
        # 登陆操作
        log = LogonOperation()
        log.logon(driver, name, pwd,repwd)
        # 获取实际结果
        result = log.getSuccessResult(driver)
        driver.quit()
        # 测试结果回写
        E=Exel_options('注册测试数据.xls')
        E.Write_Exel(0,row,expect,result)
        self.assertEqual(result,expect)

    @data(*LogonData.logon_name_error_data)
    @unpack  # 将二维列表解包成三大参数
    def testLogonNameError(self, name, pwd,repwd, expect,row):
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://192.168.72.135:90")
        # 登陆操作
        log = LogonOperation()
        log.logon(driver, name, pwd,repwd)
        # 获取实际结果
        result = log.getNameErrorResult(driver)
        driver.quit()
        E = Exel_options('注册测试数据.xls')
        E.Write_Exel(1, row, expect, result)
        # 断言
        self.assertEqual(result, expect)

    @data(*LogonData.logon_pwd_error_data)
    @unpack  # 将二维列表解包成三大参数
    def testLogonPwdError(self, name, pwd,repwd, expect,row):
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://192.168.72.135:90")
        # 登陆操作
        log = LogonOperation()
        log.login(driver, name, pwd,repwd)
        # 获取实际结果
        result = log.getPwdErrorResult(driver)
        driver.quit()
        E = Exel_options('注册测试数据.xls')
        E.Write_Exel(2, row, expect, result)
        # 断言
        self.assertEqual(result, expect)